package cn.lqz.bucttrain.mapper;

import cn.lqz.bucttrain.annotations.AutoFill;
import cn.lqz.bucttrain.enums.OperationTypeEnum;
import cn.lqz.bucttrain.enums.OrderStatusEnum;
import cn.lqz.bucttrain.pojo.dto.OrderPageQueryDTO;
import cn.lqz.bucttrain.pojo.entity.Order;
import cn.lqz.bucttrain.pojo.vo.OrderVO;
import com.github.pagehelper.Page;
import lombok.Data;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 订单
 */
@Mapper
public interface OrderMapper {
    /**
     * 查找
     * @param orderId
     * @return
     */
    @Select("select * from `order` where order_id=#{orderId}")
    Order findByOrderId(Long orderId);

    /**
     * 查找
     * @param orderPageQueryDTO
     * @return
     */
    Page<OrderVO> findBatch(OrderPageQueryDTO orderPageQueryDTO);

    /**
     * 查找该条线路上的座位
     * @param routeId
     * @param seatRowNo
     * @param seatColNo
     * @return
     */
    @Select("select * from `order` where route_id=#{routeId} and seat_row_no=#{seatRowNo} and seat_col_no=#{seatColNo} and status=#{status}")
    Order findByRouteIdAndSeatRowNoAndSeatColNoAndStatus(Long routeId,Integer seatRowNo,Integer seatColNo,Integer status);

    /**
     * 批量插入
     * @param orderList
     */
    @AutoFill(OperationTypeEnum.INSERT)
    void insertBatch(@Param("orderList") List<Order> orderList);

    /**
     * 修改
     * @param order
     */
    @AutoFill(OperationTypeEnum.UPDATE)
    void update(Order order);

    /**
     * 删除
     * @param orderId
     */
    @Delete("delete from `order` where order_id=#{orderId}")
    void deleteByOrderId(Long orderId);

    /**
     * 统计订单数量
     * @param beginDateTime
     * @param endDateTime
     * @param status
     * @return
     */
    Integer countOrderNumberByDateAndStatus(LocalDateTime beginDateTime, LocalDateTime endDateTime, Integer status);

    /**
     * 统计订单金额
     * @param beginDateTime
     * @param endDateTime
     * @param status
     * @return
     */
    BigDecimal countOrderPriceByDateAndStatus(LocalDateTime beginDateTime, LocalDateTime endDateTime, Integer status);
}
